package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.acticle.domain.StrategyCommend;
import cn.wolfcode.luowowo.acticle.query.StrategyCommendQuery;
import cn.wolfcode.luowowo.acticle.service.IStrategyCommendService;
import cn.wolfcode.luowowo.article.mapper.StrategyCommendMapper;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class StrategyCommendServiceImpl implements IStrategyCommendService {

    @Autowired
    private StrategyCommendMapper strategyCommendMapper;


    @Override
    public PageInfo query(StrategyCommendQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        return new PageInfo(strategyCommendMapper.selectForList(qo));
    }

    @Override
    public List<StrategyCommend> getTop5() {
        return strategyCommendMapper.selectTop5();
    }

    @Override
    public void saveOrUpdate(StrategyCommend commend) {
        if(commend.getId() != null){
            strategyCommendMapper.updateByPrimaryKey(commend);
        }else {
            strategyCommendMapper.insert(commend);
        }
    }
}
